<?php

class ExpFunction implements ExpCall
{
	private $name;
	private $call;

	public function __construct ($function, CliMode $mode)
	{
		$this->call = $mode->getCall($function, CliMode::ID_FUNCTION);
		$this->name = $function;

		$this->args = false;
		$this->context = false;
	}

	public function call (ArgContext $args)
	{
		return CliLib::doCall($this->name, $this->call, $args);
	}

	public function argCount ()
	{
		return -1;
	}

	public function __toString ()
	{
		return $this->name . '(';
	}

	/* ############### Static operations ############### */

	public static function addFunctions (array $functions)
	{
		foreach ($functions as $name => $call)
		{
			if (isset(self::$functions[$name]))
			{
				throw new CliIdentifierException(
					"Function '$name' already exists");
			}

			self::$functions[$name] = $call;
		}
	}

	public static function exists ($function)
	{
		return isset(self::$functions[$function]);
	}
}

?>